package com.mkyong.rest; 

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.mkyong.domain.AxesConfig;
import com.mkyong.domain.LineGraph;
import com.mkyong.domain.LineGraphDTO;
import com.mkyong.transaction.TransactionBo;

@Component
@Path("/payment")
public class PaymentService {

	@Autowired
	TransactionBo transactionBo;

	@GET
	@Path("/mkyong")
	public Response savePayment() {
		String result = transactionBo.save();
		return Response.status(200).entity(result).build();
	}
	
	@GET
	@Path("/charts/chart1")
	@Produces(MediaType.APPLICATION_JSON)
	public Response getChartData() {
		
		System.out.println("********** getChartData");
		
		Map<String, Object> response = new HashMap<String, Object>();
		
		List<LineGraphDTO> data = new ArrayList<LineGraphDTO>();
		data.add(new LineGraphDTO("1990", 85));
		data.add(new LineGraphDTO("1991", 75));
		data.add(new LineGraphDTO("1992", 90));
		data.add(new LineGraphDTO("1993", 40));
		data.add(new LineGraphDTO("1994", 30.58F));
		data.add(new LineGraphDTO("1995", 35));
		data.add(new LineGraphDTO("1996", 25));
		data.add(new LineGraphDTO("1997", 30));
		data.add(new LineGraphDTO("1998", 70));
		data.add(new LineGraphDTO("1999", 72));
		data.add(new LineGraphDTO("2000", 60.88));
		data.add(new LineGraphDTO("2001", 68));
		
		
		
//		List<AxesConfig> fields = new ArrayList<AxesConfig>();
//		fields.add(new AxesConfig("name", "Ext.data.Types.STRING"));
//		fields.add(new AxesConfig("value", "Ext.data.Types.INTEGER"));
		
		AxesConfig axesConfig = new AxesConfig("name", "value", "Year", "Profit");
		
		LineGraph lineGraph = new LineGraph();
		lineGraph.setData(data);
		//lineGraph.setXaxesTitle("Year");
		//lineGraph.setYaxesTitle("Profit");
		//lineGraph.setFields(fields);
		lineGraph.setAxesConfig(axesConfig);
		
		response.put("linechart", lineGraph);
		
		return Response.status(200).entity(response).build();
	}

}